import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { User } from './User';

export type RoomType = 'living-room' | 'living' | 'bedroom' | 'kitchen' | 'bathroom' | 'office' | 'dining-room' | 'dining' | 'game-room' | 'basement' | 'outdoor-terrace';
export type DesignStyle = 'modern' | 'traditional' | 'minimalist' | 'scandinavian' | 'industrial' | 'bohemian' | 'tribal' | 'cyberpunk' | 'coastal' | 'professional';
export type DesignStatus = 'pending' | 'processing' | 'completed' | 'failed';

@Entity('designs')
export class Design {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ name: 'user_id' })
  userId: number;

  @Column({ name: 'room_type', type: 'varchar', length: 50, nullable: true })
  roomType?: RoomType;

  @Column({ name: 'design_style', type: 'varchar', length: 50, nullable: true })
  designStyle?: DesignStyle;

  @Column({ name: 'original_image_url', type: 'text' })
  originalImageUrl: string;

  @Column({ name: 'generated_image_url', type: 'text', nullable: true })
  generatedImageUrl?: string;

  @Column({ name: 'prompt', type: 'text' })
  prompt: string;

  @Column({ name: 'status', type: 'enum', enum: ['pending', 'processing', 'completed', 'failed'], default: 'pending' })
  status: DesignStatus;

  @Column({ name: 'error_message', type: 'text', nullable: true })
  errorMessage?: string;

  @Column({ name: 'credits_used', type: 'int', default: 1 })
  creditsUsed: number;

  @Column({ name: 'openai_request_id', nullable: true })
  openaiRequestId?: string;

  @Column({ name: 'generation_time_ms', type: 'int', nullable: true })
  generationTimeMs?: number;

  @Column({ name: 'metadata', type: 'json', nullable: true })
  metadata?: Record<string, any>;

  @Column({ name: 'is_public', type: 'boolean', default: true })
  isPublic: boolean;

  @CreateDateColumn({ name: 'created_at' })
  createdAt: Date;

  @UpdateDateColumn({ name: 'updated_at' })
  updatedAt: Date;

  @ManyToOne(() => User, (user) => user.designs)
  @JoinColumn({ name: 'user_id' })
  user: User;
}